package edu.unl.bsm.CoolingLoad.testing;

import java.io.IOException;
import java.text.ParseException;

import jxl.read.biff.BiffException;

public class RegressionTest {

 	public static void main(String args[]) throws IOException, ParseException, BiffException{
//		double[][] array_X = {{1,2},{1,4},{1,7}};
//		double[] array_Y = {1,3,5};
//		double[] array_Weight = {1,1,1};
//		
//		int length = 3;
//		
//		ReadExcel Original = new ReadExcel();
//		Original.setInputFile("c:/CoolingLoadProject/All result1.xls");
//		
//	    double[][] original_data = Original.readT24_168(1);
//	    
//	    int length_origianl = original_data.length;
//	    double[] array_Y = new double[214];
//	    double[][] array_X = new double[214][17];
//	    
//	    
//	    
//	    for(int i = 5, k = 0; i < 5140&&k<214; i=i+24, k++){
//	    	array_Y[k] = original_data[i][0];
//	    	for(int j = 0; j < 11; j++){	
//	    		array_X[k][j] = original_data[i][j+1];
//	    	}
//	    }
//	    
//	    for(int i = 5, k = 0; i < 5140&&k<214; i=i+24, k++){
//	    		//t*t
//	    		array_X[k][11] = original_data[i][6] * original_data[i][6];
//	    		//t24*t24
//	    		array_X[k][12] = original_data[i][7] * original_data[i][7];
//	    		//t168*t168
//	    		array_X[k][13] = original_data[i][8] * original_data[i][8];
//	    		//t * RHt
//	    		array_X[k][14] = original_data[i][6] * original_data[i][9];
//	    		//t24 *RHt24
//	    		array_X[k][15] = original_data[i][7] * original_data[i][10];
//	    		//t168 * RHt168
//	    		array_X[k][16] = original_data[i][8] * original_data[i][11];
//	    	
//	    }
	    
	    
	    
//	    Matrix Y = new Matrix(array_Y, array_Y.length);
	    
//	    double[] test_Y = Y.getRowPackedCopy();
	    
//	    System.out.println(Arrays.toString(test_Y));
	    
	    
	    
//	    Utility.printArray(array_X, 0, array_X.length);
//	    
//	    System.out.println(Arrays.toString(array_Y));
//
//	   
////	    
////	    int length = array_Y.length;
//	    
//	    Matrix weight = Matrix.identity(length, length);
//		
//		Regression regression = new Regression();
//		
//		weight = regression.getIterWeight(array_Y, array_X, weight);
//		
//		Utility.printArraySingleLine(weight.getArray());
//		
//		Matrix cofficient = regression.getWeightedCoefficient(array_Y, array_X, weight);
//		
//		System.out.println("ARXModel(24, 168) b: " + Arrays.deepToString(cofficient.getArray()));
				
		//		List<double[][]> weightPrimePrime = new ArrayList<double[][]>();
				
		//		weightPrimePrime = regression.getWeightPrimePrime(weight);
				
		//		double minLeastSquare = regression.getSecondStageWeightedLeastSquare(array_Y, array_X, weightPrimePrime);
				
		//		System.out.println("Min Least Square: " + minLeastSquare);
				
		//		regression.getFFCofficient(array_Y, array_X, weightPrimePrime);
		
		/**
		ARXFirstWDProvider test = new ARXFirstWDProvider();
		test.setHistdata();
		for(int i = 1; i <= 6; i++){
			
				test.setARXHistmodel(i, 0);
		//		
//				Utility.printArraySingleLine(test.getARXmodel_X());
//			
//				System.out.println(Arrays.toString(test.getARXmodel_Y()));
				
				double[][] array_X = test.getARXmodel_X();
				
				double[] array_Y = test.getARXmodel_Y();
				
				int length = array_Y.length;
			    
			    Matrix weight = Matrix.identity(length, length);
				
				Regression regression = new Regression();
				
				weight = regression.getIterWeight(array_Y, array_X, weight);
				
//				Utility.printArraySingleLine(weight.getArray());
				
				Matrix cofficient = regression.getWeightedCoefficient(array_Y, array_X, weight);
				
				System.out.println("ARXModel("+i+"," + (i+1) + ", 24) b: " + Arrays.deepToString(cofficient.getArray()));
				}
		
		ARXSecondWDProvider second = new ARXSecondWDProvider();
		
		
		second.setHistdata();
		second.setARXHistmodel(0);
		//		
//		Utility.printArraySingleLine(second.getARXmodel_X());
//	
//		System.out.println(Arrays.toString(second.getARXmodel_Y()));
		
		double[][] array_X = second.getARXmodel_X();
		
		double[] array_Y = second.getARXmodel_Y();
		
		int length = array_Y.length;
	    
	    Matrix weight = Matrix.identity(length, length);
		
		Regression regression = new Regression();
		
		weight = regression.getIterWeight(array_Y, array_X, weight);
		
//				Utility.printArraySingleLine(weight.getArray());
		
		Matrix cofficient = regression.getWeightedCoefficient(array_Y, array_X, weight);
		
		System.out.println("ARXModel(24, 168) b: " + Arrays.deepToString(cofficient.getArray()));
				
		//		List<double[][]> weightPrimePrime = new ArrayList<double[][]>();
				
		//		weightPrimePrime = regression.getWeightPrimePrime(weight);
				
		//		double minLeastSquare = regression.getSecondStageWeightedLeastSquare(array_Y, array_X, weightPrimePrime);
				
		//		System.out.println("Min Least Square: " + minLeastSquare);
				
		//		regression.getFFCofficient(array_Y, array_X, weightPrimePrime);
		 */
		
//	}

	}
}
